package org.example.test1;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class HalfYearGroup extends Group implements RangeGenerable{
    public HalfYearGroup(LocalDate date) {
        super(date);
    }
    @Override
    public String getDisplayName() {
        int half=date.getMonthValue()-1/6+1;
        return String.format(Unit.HALF_YEAR.getFormatter(),date.getYear(),(half==1?"上":"下"));
    }

    @Override
    public int compareTo(LocalDate o) {
        return 0;
    }

    @Override
    public Map<Group, Counter> generate(LocalDate start, LocalDate end) {//按所选时间生成半年组
        Map<Group, Counter> result = new HashMap<>();
        LocalDate current= start.with(TemporalAdjusters.firstDayOfMonth());
        while (current.isBefore(end)) {
            result.put(new HalfYearGroup(current),new Counter(0,0));
            current=current.plusMonths(6).with(TemporalAdjusters.firstDayOfMonth());
        }
        return result;
    }
}
